<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="门诊卡id" prop="outpatientid">
        <el-input v-model="queryParams.outpatientid" placeholder="请输入门诊卡id" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="医生ID" prop="doctorid">
        <el-input v-model="queryParams.doctorid" placeholder="请输入医生ID" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="诊断类别" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.sys_reception_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['outpatient:receiverecord:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handlejiancha"
          v-hasPermi="['outpatient:receiverecord:edit']">检查</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handlejianyan"
          v-hasPermi="['outpatient:receiverecord:edit']">检验</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handlezhenduan"
          v-hasPermi="['outpatient:receiverecord:edit']">诊断</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handlechuzhi"
          v-hasPermi="['outpatient:receiverecord:edit']">处置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['outpatient:receiverecord:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['outpatient:receiverecord:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="receiverecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="接诊记录表id" align="center" prop="opdoctorreceiverecordid" />
      <el-table-column label="门诊卡id" align="center" prop="outpatientid" />
      <el-table-column label="医生ID" align="center" prop="doctorid" />
      <el-table-column label="诊断类别" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_reception_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 1" size="mini" type="text" icon="el-icon-edit"
            @click="handlezhuyuan(scope.row)" v-hasPermi="['outpatient:receiverecord:edit']">住院</el-button>
          <el-button v-if="scope.row.status == 2" size="mini" type="text" icon="el-icon-edit"
            @click="handlejiezhen(scope.row)" v-hasPermi="['outpatient:receiverecord:edit']">接诊</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改接诊记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-row :gutter="20">
          <!--部门数据-->
          <el-col :span="8" :xs="24">
            <div class="head-container">
              <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                :filter-node-method="filterNode" ref="tree" default-expand-all @node-click="handleNodeClick" />
            </div>
          </el-col>
          <el-col :span="16" :xs="24">
            <el-table v-loading="loading" ref="userTable" :data="userList" @current-change="handleCurrentChange">
              <el-table-column type="selection"  align="center" />
              <el-table-column label="用户编号" align="center" key="userId" prop="userId"  />
              <el-table-column label="用户名称" align="center" key="userName" prop="userName" :show-overflow-tooltip="true" />
              <el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" />
            </el-table>
          </el-col>
        </el-row>
        <el-form-item label="门诊卡id" prop="outpatientid">
          <el-input v-model="form.outpatientid" placeholder="请输入门诊卡id" />
        </el-form-item>
        <el-form-item label="医生ID" prop="doctorid">
          <el-input v-model="form.doctorid" placeholder="请输入医生ID" />
        </el-form-item>
        <el-form-item label="1门诊2住院">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_reception_status" :key="dict.value" :label="parseInt(dict.value)">
              {{dict.label}}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加Pacs影像信息-->
    <el-dialog :title="title" :visible.sync="open1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="消费事项" prop="partname">
          <el-select v-model="form.partname" placeholder="请选择" clearable size="small">
            <el-option v-for="dict in dict.type.sys_pacs_info" :key="dict.label" :label="dict.label"
              :value="dict.label" />
          </el-select>
        </el-form-item>

        <el-row :gutter="20">
          <!--部门数据-->
          <el-col :span="8" :xs="24">
            <div class="head-container">
              <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                :filter-node-method="filterNode" ref="tree" default-expand-all @node-click="handleNodeClick" />
            </div>
          </el-col>
          <el-col :span="16" :xs="24">
            <el-table v-loading="loading" ref="userTable" :data="userList" @current-change="handleCurrentChange">
              <el-table-column type="selection"  align="center" />
              <el-table-column label="用户编号" align="center" key="userId" prop="userId"  />
              <el-table-column label="用户名称" align="center" key="userName" prop="userName" :show-overflow-tooltip="true" />
              <el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" />
            </el-table>
          </el-col>
        </el-row>
        <el-form-item label="门诊卡id" prop="outpatientid">
          <el-input v-model="form.outpatientid" placeholder="请输入门诊卡id" />
        </el-form-item>
        <el-form-item label="门诊医生接诊记录ID" prop="receiverecordid">
          <el-input v-model="form.receiverecordid" placeholder="请输入门诊医生接诊记录ID" />
        </el-form-item>
        <el-form-item label="患者ID" prop="personid">
          <el-input v-model="form.personid" placeholder="请输入患者ID" />
        </el-form-item>
        <el-form-item label="接诊记录ID" prop="opdoctorreceiverecordid">
          <el-input v-model="form.opdoctorreceiverecordid" placeholder="请输入接诊记录ID" />
        </el-form-item>
        <el-form-item label="事项数量" prop="partnumber">
          <el-input v-model="form.partnumber" placeholder="请输入事项数量" />
        </el-form-item>
        <el-form-item label="单价" prop="partmoney">
          <el-input v-model="form.partmoney" placeholder="请输入单价" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="jianchatijiao">支付</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 确认订单信息-->
    <el-dialog :title="title" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="金额" prop="partmoney" disabled>
          <el-input v-model="form.partmoney" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="门诊卡id" prop="outpatientid">
          <el-input v-model="form.outpatientid" placeholder="请输入门诊卡id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="querendingdan">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 检验弹出框-->
    <el-dialog :title="title" :visible.sync="open3" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="消费事项" prop="partname">
          <el-select v-model="form.partname" placeholder="请选择" clearable size="small">
            <el-option v-for="dict in dict.type.sys_lis_info" :key="dict.label" :label="dict.label"
              :value="dict.label" />
          </el-select>
        </el-form-item>

        <el-row :gutter="20">
          <!--部门数据-->
          <el-col :span="8" :xs="24">
            <div class="head-container">
              <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                :filter-node-method="filterNode" ref="tree" default-expand-all @node-click="handleNodeClick" />
            </div>
          </el-col>
          <el-col :span="16" :xs="24">
            <el-table v-loading="loading" ref="userTable" :data="userList" @current-change="handleCurrentChange">
              <el-table-column type="selection"  align="center" />
              <el-table-column label="用户编号" align="center" key="userId" prop="userId"  />
              <el-table-column label="用户名称" align="center" key="userName" prop="userName" :show-overflow-tooltip="true" />
              <el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" />
            </el-table>
          </el-col>
        </el-row>
        <el-form-item label="门诊卡id" prop="outpatientid">
          <el-input v-model="form.outpatientid" placeholder="请输入门诊卡id" />
        </el-form-item>
        <el-form-item label="门诊医生接诊记录ID" prop="receiverecordid">
          <el-input v-model="form.receiverecordid" placeholder="请输入门诊医生接诊记录ID" />
        </el-form-item>
        <el-form-item label="患者ID" prop="personid">
          <el-input v-model="form.personid" placeholder="请输入患者ID" />
        </el-form-item>
        <el-form-item label="接诊记录ID" prop="opdoctorreceiverecordid">
          <el-input v-model="form.opdoctorreceiverecordid" placeholder="请输入接诊记录ID" />
        </el-form-item>
        <el-form-item label="事项数量" prop="partnumber">
          <el-input v-model="form.partnumber" placeholder="请输入事项数量" />
        </el-form-item>
        <el-form-item label="单价" prop="partmoney">
          <el-input v-model="form.partmoney" placeholder="请输入单价" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="jianyantijiao">支付</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- *******************************************************诊断*********************************-->
    <el-dialog :title="title" :visible.sync="open4" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="病名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入病名称" />
        </el-form-item>
        <el-form-item label="描述症状" prop="description">
          <el-input v-model="form.description" placeholder="请输入描述症状" />
        </el-form-item>
        <el-form-item label="医嘱" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入医嘱" />
        </el-form-item>
        <el-form-item label="门诊医生接诊记录ID" prop="opdoctorreceiverecordid">
          <el-input v-model="form.opdoctorreceiverecordid" placeholder="请输入门诊医生接诊记录ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="zhenduantijiao">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- ——————————————————————————————————————————————————————————处置——————————————————————————————————————-->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="药品名称" prop="name">
        	<el-select v-model="form.name" placeholder="请选择药品名称" @change="change3">
        		<el-option v-for="dict in this.infoList" v-if="dict.statue==1" :label="dict.name" :key="dict.id"
        			:value="dict.name"></el-option>
        	</el-select>
        </el-form-item>
        <el-form-item label="事项数量" prop="partnumber">
          <el-input v-model="form.partnumber" placeholder="请输入事项数量" />
        </el-form-item>
        <el-form-item label="单价" prop="partmoney">
          <el-input v-model="form.partmoney" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="医生治疗结果ID" prop="opdoctorresultid">
          <el-input v-model="form.opdoctorresultid" placeholder="请输入医生治疗结果ID" />
        </el-form-item>
        <el-form-item label="诊断结果" prop="partname">
          <el-input v-model="form.partname" placeholder="请输入医生治疗结果ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="chuzhitijiao">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import {
    listReceiverecord,
    getReceiverecord,
    delReceiverecord,
    addReceiverecord,
    updateReceiverecord
  } from "@/api/outpatient/receiverecord";

  import {
    listUser,
    getUser,
    delUser,
    addUser,
    updateUser,
    resetUserPwd,
    changeUserStatus
  } from "@/api/system/user";
  import {
    getToken
  } from "@/utils/auth";
  import {
    treeselect
  } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  /* ************************************************看病流程*******************************/
  import {
    listAction,
    getAction,
    delAction,
    addAction,
    updateAction
  } from "@/api/outpatient/action";

/* ************************************************门诊卡信息************************************ */
  import {
    listInfo,
    getInfo,
    delInfo,
    addInfo,
    updateInfo
  } from "@/api/outpatient/info";

  /* */
  import {
    listInfo1,
    getInfo1,
    delInfo1,
    addInfo1,
    updateInfo1
  } from "@/api/pacs/info";

  import {
    listArchives,
    getArchives,
    delArchives,
    addArchives,
    updateArchives
  } from "@/api/outpatient/archives";

  import {
    listResulthandle,
    getResulthandle,
    delResulthandle,
    addResulthandle,
    updateResulthandle
  } from "@/api/outpatient/resulthandle";

import { listBill, getBill, delBill, addBill, updateBill } from "@/api/cost/bill";

  import {
    listDetail,
    getDetail,
    delDetail,
    addDetail,
    updateDetail
  } from "@/api/cost/detail";

  import {
    listLisinfo,
    getLisinfo,
    delLisinfo,
    addLisinfo,
    updateLisinfo
  } from "@/api/pacs/lisinfo";

  import {
    listResult,
    getResult,
    delResult,
    addResult,
    updateResult
  } from "@/api/outpatient/result";



  export default {
    name: "Receiverecord",
    dicts: ['sys_reception_status','sys_pacs_info','sys_lis_info'],
    data() {
      return {
        // 用户表格数据
        userList: null,
        currentRow: null,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 接诊记录表格数据
        receiverecordList: [],
        // 药品信息表格数据
        infoList: [],
        // 部门树选项
        deptOptions: undefined,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //添加pacs影像信息是否显示弹出框
        open1: false,
        open2: false,
        open3: false,
        open4: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          outpatientid: null,
          doctorid: null,
          status: null,
          createTime: null,
          personid:null
        },
        queryParams1: {
          outpatientid: null,
        },
        queryParams2: {
          opdoctorreceiverecordid: null,
        },


        // 表单参数
        form: {},
        form1:{
          money:null,
          id:null
        },
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
      this.getTreeselect();
    },
    methods: {
      /** 查询接诊记录列表 */
      getList() {
        this.loading = true;
        listReceiverecord(this.queryParams).then(response => {
          this.receiverecordList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      //节点按钮
      handleNodeClick(data) {
        this.queryParams.deptId = data.id;
        this.handleUserQuery();
      },
      //
      handleUserQuery() {
        this.queryParams.pageNum = 1;
        this.getUserList();
      },
      /** 查询用户列表 */
      getUserList() {
        this.loading = true;
        listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //
      handleCurrentChange(val) {
        if(val!=null){
          console.log("-===="+val)
          this.form.doctorid = val.userId;
          this.form.receiverecordid = val.userId;
        }
      },
      setCurrent(row){
        this.$refs.userTable.setCurrentRow(row);
      },
     // 筛选节点
     filterNode(value, data) {
       if (!value) return true;
       return data.label.indexOf(value) !== -1;
     },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id:null,
          opdoctorreceiverecordid: null,
          outpatientid: null,
          doctorid: null,
          status: 0,
          createTime: null,
          receiverecordid: null,
          partmoney:null,
          partnumber:null,
          partname:null,
          name:null,
          money:null,
          money1:null,
          personid:null,
          type:0,
          billid:null,
          description:null,
          remark:null,
          opdoctorresultid:null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.opdoctorreceiverecordid)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加接诊记录";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        getReceiverecord(opdoctorreceiverecordid).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改接诊记录";
        });
      },
      //住院按钮
      handlezhuyuan(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        getReceiverecord(opdoctorreceiverecordid).then(response => {
          response.data.status = 2;
          this.form = response.data;
          updateReceiverecord(this.form).then(response => {
            this.$modal.msgSuccess("住院成功");
            this.getList()
          })
        });
      },
      //接诊按钮
      handlejiezhen(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        getReceiverecord(opdoctorreceiverecordid).then(response => {
          response.data.status = 1;
          this.form = response.data;
          updateReceiverecord(this.form).then(response => {
            this.$modal.msgSuccess("接诊成功");
            this.getList()
          })
        });
      },

      /**药品消费事项**/
      change3() {
      	for (let i of this.infoList) {
      		if (i.name == this.form.name) {
      			this.formp.partmoney = i.sellunitprice;
      		}
      	}
      },

      /* **********************************************检查按钮*************************************/
      handlejiancha(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        /* 查门诊卡里的余额*/
        getReceiverecord(opdoctorreceiverecordid).then(response => {
        const outpatientid = response.data.outpatientid
        getInfo(outpatientid).then(r => {
            this.form = response.data;
            this.form.money=r.data.money
            this.queryParams.personid=r.data.personid
            getArchives(r.data.personid).then(re => {
              this.form.personid = re.data.id;
            });
            if(response.data.status==1){

                listInfo1(this.queryParams).then(a => {
              /* 查Pacsz中所对应的个人档案的信息是否为空*/
                  if(a.rows.length==0){
                    this.open1 = true;
                      this.title = "添加Pacs信息记录";
                  }else{
                    this.$modal.msgSuccess("已做检查，请进行其他操作");
                  }
                });
            }else{
              this.$modal.msgSuccess("请选择接诊的进行操作");
            }

          });
        });
      },

      /* ***********************************************检查提交***************************************/
      jianchatijiao() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            console.log("门诊信息卡"+this.form.partmoney)
            if(parseFloat(this.form.money)>=parseFloat(this.form.partmoney)){
              this.form.money=parseFloat(this.form.money)-parseFloat(this.form.partmoney)
              this.form.id=this.form.outpatientid
              this.queryParams1.outpatientid=this.form.outpatientid
              this.form.type=1
              /* 查看患者账单是否有数据*/
                listBill(this.queryParams1).then(o => {
                console.log(o.rows)
                /* 没有数据就进行增加操作*/
                if(o.rows.length==0){

                updateInfo(this.form).then(response => {
                  this.form.name=this.form.partname
                    /* 增加看病流程信息*/
                    addAction(this.form).then(response => {
                      this.form.money=this.form.partmoney
                      /* 增加账单*/
                    addBill(this.form).then(resp => {
                      listBill(this.queryParams1).then(z => {

                    console.log(resp.rows)

                      /* 增加账单明细*/
                      this.form.billid=z.rows[0].id
                      this.form.id=new Date().getTime()
                      addDetail(this.form).then(response => {
                  /* 增加pacs信息*/
                    addInfo1(this.form).then(response => {
                          this.open1 = false;
                          this.open2 = true;
                      });
                      });
                      });
                    });
                  });
                });
                /* 如果有数据就进行修改*/
                }else{
                  updateInfo(this.form).then(response => {
                    this.form.name=this.form.partname
                      /* 增加看病流程信息*/
                      addAction(this.form).then(response => {
                        this.form.money=this.form.partmoney
                        /* 修改账单*/
                        this.form1.id=o.rows[0].id
                        this.form1.money=parseFloat(this.form.partmoney)+parseFloat(o.rows[0].money)
                      updateBill(this.form1).then(resp => {
                      console.log(resp.rows)

                        /* 增加账单明细*/
                        this.form.billid=o.rows[0].id
                        this.form.id=new Date().getTime()
                        addDetail(this.form).then(response => {
                    /* 增加pacs信息*/
                      addInfo1(this.form).then(response => {
                            this.open1 = false;
                            this.open2 = true;
                        });
                        });
                      });
                    });
                  });
                }
                });
            }else{
              this.$modal.msgSuccess("余额不足请充值");
            }
          }
        });
      },

      /* **********************************************检验按钮*************************************/
      handlejianyan(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        /* 查门诊卡里的余额*/
        getReceiverecord(opdoctorreceiverecordid).then(response => {
        const outpatientid = response.data.outpatientid
        getInfo(outpatientid).then(r => {
            this.form = response.data;
            this.form.money=r.data.money
            this.queryParams.personid=r.data.personid
            getArchives(r.data.personid).then(re => {
              this.form.personid = re.data.id;
            });
            if(response.data.status==1){
                listLisinfo(this.queryParams).then(a => {
                  listInfo1(this.queryParams).then(b => {
                    console.log(b.rows)
                    if(b.rows[0].status==2){
                      if(a.rows.length==0){
                        this.open3 = true;
                          this.title = "添加Lis信息记录";
                      }else{
                        this.$modal.msgSuccess("已做检验，请进行其他操作");
                      }
                    }else{
                      this.$modal.msgSuccess("有未执行的检查，请执行完在进行检验");
                    }
              /* 查Pacsz中所对应的个人档案的信息是否为空*/

                  });
                });
            }else{
              this.$modal.msgSuccess("请选择接诊的进行操作");
            }

          });
        });
      },

      /* ***********************************************检验提交***************************************/
      jianyantijiao() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            console.log("门诊信息卡"+this.form.partmoney)
            if(parseFloat(this.form.money)>=parseFloat(this.form.partmoney)){
              this.form.money=parseFloat(this.form.money)-parseFloat(this.form.partmoney)
              this.form.id=this.form.outpatientid
              this.queryParams1.outpatientid=this.form.outpatientid
              this.form.type=2
              /* 查看患者账单是否有数据*/
                listBill(this.queryParams1).then(o => {
                console.log(o.rows)
                /* 没有数据就进行增加操作*/
                if(o.rows.length==0){

                updateInfo(this.form).then(response => {
                  this.form.name=this.form.partname
                    /* 增加看病流程信息*/
                    addAction(this.form).then(response => {
                      this.form.money=this.form.partmoney
                      /* 增加账单*/
                    addBill(this.form).then(resp => {
                      listBill(this.queryParams1).then(z => {

                    console.log(resp.rows)

                      /* 增加账单明细*/
                      this.form.billid=z.rows[0].id
                      this.form.id=new Date().getTime()
                      addDetail(this.form).then(response => {
                  /* 增加lis信息*/
                  console.log("name---"+this.form.name)
                    addLisinfo(this.form).then(response => {
                      console.log("数据----"+this.form)
                          this.open3 = false;
                          this.open2 = true;
                      });
                      });
                      });
                    });
                  });
                });
                /* 如果有数据就进行修改*/
                }else{
                  updateInfo(this.form).then(response => {
                    this.form.name=this.form.partname
                      /* 增加看病流程信息*/
                      addAction(this.form).then(response => {
                        this.form.money=this.form.partmoney
                        /* 修改账单*/
                        this.form1.id=o.rows[0].id
                        this.form1.money=parseFloat(this.form.partmoney)+parseFloat(o.rows[0].money)
                      updateBill(this.form1).then(resp => {
                      console.log(resp.rows)

                        /* 增加账单明细*/
                        this.form.billid=o.rows[0].id
                        this.form.id=new Date().getTime()
                        addDetail(this.form).then(response => {
                    /* 增加pacs信息*/
                    console.log("name---"+this.form.name)
                    console.log("partname---"+this.form.partname)
                      addLisinfo(this.form).then(response => {
                        console.log("数据----"+this.form)
                            this.open3 = false;
                            this.open2 = true;
                        });
                        });
                      });
                    });
                  });
                }
                });
            }else{
              this.$modal.msgSuccess("余额不足请充值");
            }
          }
        });
      },
      /* ***************************************************处置按钮************************************************/
      handlechuzhi(row) {
              this.reset();
              const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
              /* 查门诊卡里的余额*/
              getReceiverecord(opdoctorreceiverecordid).then(response => {
              const outpatientid = response.data.outpatientid
              getInfo(outpatientid).then(r => {
                  this.form = response.data;
                  this.form.money=r.data.money
                  this.queryParams.personid=r.data.personid
                  this.queryParams2.opdoctorreceiverecordid=r.data.opdoctor
                  getArchives(r.data.personid).then(re => {
                    this.form.personid = re.data.id;
                  });
                  if(response.data.status==1){

                      listlistResulthandle(this.queryParams2).then(a => {
                        listLisinfo(this.queryParams).then(b => {
                          if(b.rows[0].status==2){
                    /* 查Pacsz中所对应的个人档案的信息是否为空*/
                        if(a.rows.length==0){
                          this.open1 = true;
                            this.title = "添加Pacs信息记录";
                        }else{
                          this.$modal.msgSuccess("已做诊断，请进行其他操作");
                        }
                        }else{
                          this.$modal.msgSuccess("有未执行的检验，请执行完在进行诊断");
                        }
                        });
                      });
                  }else{
                    this.$modal.msgSuccess("请选择接诊的进行操作");
                  }

                });
              });
            },

            /* ***********************************************处置提交***************************************/
            chuzhitijiao() {
              this.$refs["form"].validate(valid => {
                if (valid) {
                  console.log("门诊信息卡"+this.form.partmoney)
                  if(parseFloat(this.form.money)>=parseFloat(this.form.partmoney)){
                    this.form.money=parseFloat(this.form.money)-parseFloat(this.form.partmoney)
                    this.form.id=this.form.outpatientid
                    this.queryParams1.outpatientid=this.form.outpatientid
                    this.form.type=1
                    /* 查看患者账单是否有数据*/
                      listBill(this.queryParams1).then(o => {
                      console.log(o.rows)
                      /* 没有数据就进行增加操作*/
                      if(o.rows.length==0){

                      updateInfo(this.form).then(response => {
                        this.form.name=this.form.partname
                          /* 增加看病流程信息*/
                          addAction(this.form).then(response => {
                            this.form.money=this.form.partmoney
                            /* 增加账单*/
                          addBill(this.form).then(resp => {
                            listBill(this.queryParams1).then(z => {

                          console.log(resp.rows)

                            /* 增加账单明细*/
                            this.form.billid=z.rows[0].id
                            this.form.id=new Date().getTime()
                            addDetail(this.form).then(response => {
                        /* 增加pacs信息*/
                          addInfo1(this.form).then(response => {
                                this.open1 = false;
                                this.open2 = true;
                            });
                            });
                            });
                          });
                        });
                      });
                      /* 如果有数据就进行修改*/
                      }else{
                        updateInfo(this.form).then(response => {
                          this.form.name=this.form.partname
                            /* 增加看病流程信息*/
                            addAction(this.form).then(response => {
                              this.form.money=this.form.partmoney
                              /* 修改账单*/
                              this.form1.id=o.rows[0].id
                              this.form1.money=parseFloat(this.form.partmoney)+parseFloat(o.rows[0].money)
                            updateBill(this.form1).then(resp => {
                            console.log(resp.rows)

                              /* 增加账单明细*/
                              this.form.billid=o.rows[0].id
                              this.form.id=new Date().getTime()
                              addDetail(this.form).then(response => {
                          /* 增加pacs信息*/
                            addInfo1(this.form).then(response => {
                                  this.open1 = false;
                                  this.open2 = true;
                              });
                              });
                            });
                          });
                        });
                      }
                      });
                  }else{
                    this.$modal.msgSuccess("余额不足请充值");
                  }
                }
              });
            },

      querendingdan() {

              this.$modal.msgSuccess("订单提交成功");
              this.open1 = false;
              this.open2 = false;
              this.getList();
      },

      /* **********************************************诊断按钮*************************************/
      handlezhenduan(row) {
        this.reset();
        const opdoctorreceiverecordid = row.opdoctorreceiverecordid || this.ids
        getReceiverecord(opdoctorreceiverecordid).then(response => {
          console.log(response.data)
        const outpatientid = response.data.outpatientid
        this.queryParams2=response.data
        this.form=response.data
            if(response.data.status==1){
                listResult(this.queryParams2).then(a => {
                  console.log(a.rows)
              /* 查Pacsz中所对应的个人档案的信息是否为空*/
                  if(a.rows.length==0){
                    this.open4 = true;
                      this.title = "诊断";
                  }else{
                    this.$modal.msgSuccess("已有诊断，请进行其他操作");
                  }
                });
            }else{
              this.$modal.msgSuccess("请选择接诊的进行操作");
            }

            //});
          });
      },

      /* ***********************************************诊断提交***************************************/
      zhenduantijiao() {
        this.$refs["form"].validate(valid => {
          if (valid) {
                listResult(this.queryParams2).then(o => {
                    /* 看病结果*/
                    console.log(this.form)
                      addResult(this.form).then(response => {
                        this.$modal.msgSuccess("诊断成功");
                          this.open4 = false;
                      });
                });
          }
      });
      },


      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.opdoctorreceiverecordid != null) {
              updateReceiverecord(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addReceiverecord(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const opdoctorreceiverecordids = row.opdoctorreceiverecordid || this.ids;
        this.$modal.confirm('是否确认删除接诊记录编号为"' + opdoctorreceiverecordids + '"的数据项？').then(function() {
          return delReceiverecord(opdoctorreceiverecordids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('outpatient/receiverecord/export', {
          ...this.queryParams
        }, `receiverecord_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
